package com.mnsq.subject.controller;

import com.mnsq.common.bean.annotation.UserInfoRequired;
import com.mnsq.common.bean.document.SubjectMg;
import com.mnsq.common.controller.BaseMongoController;
import com.mnsq.subject.bean.condition.MongoSubjectCondition;
import com.mnsq.subject.service.MongoDbService;
import matrix.module.common.bean.Result;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 周俭
 */
@RestController
@RequestMapping("/api/bmg")
public class MongoController extends BaseMongoController<SubjectMg, MongoSubjectCondition> {

    @Autowired
    private MongoDbService mongoDbService;

    @ApiOperation("审核通过，将内容放入mongo")
    @UserInfoRequired(required = true)
    @PostMapping("/agree")
    public Result confirmSubject(@RequestBody MongoSubjectCondition documentCondition) {
        documentCondition.detailValid();
        String unique = MapUtils.getString(documentCondition.getEqParams(), "unique");
        if(StringUtils.isBlank(unique)){
            return Result.fail("请选择审核条目");
        }
        mongoDbService.agree(documentCondition);
        return Result.success(true);
    }

    @ApiOperation("审核未通过，将内容状态更新")
    @UserInfoRequired(required = true)
    @PostMapping("/disagree")
    public Result disagreeSubject(@RequestBody MongoSubjectCondition documentCondition) {
        documentCondition.detailValid();
        mongoDbService.disagree(documentCondition);
        return Result.success(true);
    }
}
